# !/usr/usuari/des python
#  -*- coding: utf-8 -*-
"""
@Author        : itgnay
@Time          : 2022/12/21 17:40
@FileName      : N皇后问题.py
@LastEditors   : None
@Editors       : PyCharm
"""

queens = []  # 每一行一个皇后，只需要记录每行皇后所在的列数
N = int(input('请输入皇后个数：\n'))  # 皇后个数


def check(queens, q_c):
    q_r = len(queens)
    for r in range(len(queens)):
        c = queens[r]
        if q_r + q_c == c + r or q_r - r == q_c - c or q_c == c:
            return False
    return True


count = 0


def dfs(queens, N):
    global count
    if len(queens) == N:
        count += 1
    else:
        for q_c in range(N):
            if check(queens, q_c):
                dfs(queens + [q_c], N)


dfs(queens, N)
print(count)
